package com.laowang.project.system.controller;

import java.util.List;

import com.laowang.project.system.domain.MyCyhShop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.laowang.framework.aspectj.lang.annotation.Log;
import com.laowang.framework.aspectj.lang.enums.BusinessType;

import org.springframework.web.bind.annotation.*;
import com.laowang.project.system.domain.MyCyhImg;
import com.laowang.project.system.service.MyCyhImgService;
import com.laowang.framework.web.controller.BaseController;
import com.laowang.framework.web.domain.AjaxResult;
import com.laowang.common.utils.poi.ExcelUtil;
import com.laowang.framework.web.page.TableDataInfo;

/**
 * 商家入驻的图片Controller
 *
 * @author laowang
 * @date 2023-05-05
 */
@Api(tags = "商家入驻的图片接口")
@RestController
@RequestMapping("/shopImg")
public class MyCyhImgController extends BaseController {
    @Autowired
    private MyCyhImgService myCyhImgService;

    @ApiOperation(value = "小程序端 商家入驻的图片列表",notes = "")
    @GetMapping("/web/list")
    public AjaxResult weblist() {
        MyCyhImg myCyhImg =new MyCyhImg();
        myCyhImg.setIsEnable("1");
        List<MyCyhImg> list = myCyhImgService.selectMyCyhImgList(myCyhImg);
        for (MyCyhImg cyhImg : list) {
            if (cyhImg.getId() !=null){
                if (cyhImg.getId().equals(1)){
                    cyhImg.setPlanName("联盟商家");
                }else if (cyhImg.getId().equals(2)){
                    cyhImg.setPlanName("精选商家");
                }else if (cyhImg.getId().equals(3)){
                    cyhImg.setPlanName("理事商家");
                }if (cyhImg.getId().equals(4)){
                    cyhImg.setPlanName("副会长商家");
                }
            }
        }
        return AjaxResult.success("操作成功",list);
    }



    /**
     * 查询商家入驻的图片列表
     */
    @ApiOperation(value = "查询商家入驻的图片列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:shopImg:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyCyhImg myCyhImg) {
        startPage();
        List<MyCyhImg> list = myCyhImgService.selectMyCyhImgList(myCyhImg);
        return getDataTable(list);
    }

    /**
     * 导出商家入驻的图片列表
     */
    @ApiOperation(value = "导出商家入驻的图片列表",notes = "")
    @PreAuthorize("@ss.hasPermi('my:shopImg:export')")
    @Log(title = "商家入驻的图片", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MyCyhImg myCyhImg) {
        List<MyCyhImg> list = myCyhImgService.selectMyCyhImgList(myCyhImg);
        ExcelUtil<MyCyhImg> util = new ExcelUtil<MyCyhImg>(MyCyhImg.class);
        return util.exportExcel(list, "merchantImg");
    }

    /**
     * 获取商家入驻的图片详细信息
     */
    @ApiOperation(value = "获取商家入驻的图片详细信息",notes = "")
    @PreAuthorize("@ss.hasPermi('my:shopImg:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(myCyhImgService.selectMyCyhImgById(id));
    }

    /**
     * 新增商家入驻的图片
     */
    @ApiOperation(value = "新增商家入驻的图片",notes = "")
    @PreAuthorize("@ss.hasPermi('my:shopImg:add')")
    @Log(title = "商家入驻的图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyCyhImg myCyhImg) {
        return toAjax(myCyhImgService.insertMyCyhImg(myCyhImg));
    }

    /**
     * 修改商家入驻的图片
     */
    @ApiOperation(value = "修改商家入驻的图片",notes = "")
    @PreAuthorize("@ss.hasPermi('my:shopImg:edit')")
    @Log(title = "商家入驻的图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyCyhImg myCyhImg) {
        return toAjax(myCyhImgService.updateMyCyhImg(myCyhImg));
    }

    /**
     * 删除商家入驻的图片
     */
    @ApiOperation(value = "删除商家入驻的图片",notes = "")
    @PreAuthorize("@ss.hasPermi('my:shopImg:remove')")
    @Log(title = "商家入驻的图片", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(myCyhImgService.deleteMyCyhImgByIds(ids));
    }
}
